package com.example.controller;

import com.example.entity.ImMessage;
import com.example.service.ImMessageService;
import com.example.vo.IdHolder;
import com.example.vo.Result;
import io.swagger.annotations.Api;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author circle48
 */
@RestController
@Slf4j
@Api(tags = "聊天端口")
@RequestMapping("/im")
public class ImMessageController {
    @Resource
    private ImMessageService imMessageService;
    /**
     * 获取与特定客服交流过的所有用户ID列表
     * @param waiterId 客服的用户ID
     * @return 用户ID列表的响应
     */
    @GetMapping("/{waiterId}/users")
    public Result getUserListForCustomer(@PathVariable("waiterId") Long waiterId) {
        return imMessageService.getUserIdsByWaiterId(waiterId);

    }


    /**
     * 获取与某个用户的历史记录
     * @param customerId 对方的用户ID
     * @return 离线消息列表的响应
     */
    @GetMapping("/offline/{customerId}")
    public Result<List<ImMessage>> getOfflineMessages(@PathVariable Long customerId) {
        // 获取当前用户ID
        Long currentUserId = IdHolder.getUserId();
        // 从数据库获取离线消息
        List<ImMessage> messages = imMessageService.getOfflineMessages(currentUserId, customerId);
        return Result.ok(messages);
    }


}
